//
//  IndexViewController.m
//  JianChaRiBao
//
//  Created by yuzhou on 13-5-9.
//  Copyright (c) 2013年 wzyk. All rights reserved.
//

#import "IndexViewController.h"
#import "MainViewController.h"
#import "NewspaperViewController.h"
#import "MagazineViewController.h"
#import "ListenViewController.h"
#import "NovelViewController.h"
#import "NewspaperInfoViewController.h"
#import "JinRiMagazineViewController.h"
@interface IndexViewController ()
{
//    MainViewController *mainViewController;
    NewspaperInfoViewController *newspaperInfoViewController;
    
    NewspaperViewController *newspaperViewController;
    MagazineViewController *magazineViewController;
    ListenViewController *listenViewController;
    NovelViewController *novelViewController;
    JinRiMagazineViewController *jinRiMagazineViewController;
}
@end

@implementation IndexViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.view.frame = self.parentViewController.view.bounds;
    
    if (newspaperInfoViewController == nil) {
        newspaperInfoViewController = [[NewspaperInfoViewController alloc] initWithNibName:@"NewspaperInfoViewController" bundle:nil];
        newspaperInfoViewController.isHomePage = YES;
    }
    [self addChildViewController:newspaperInfoViewController];
}

- (void)switchToIndex:(int)index
{
    switch (index) {
        case kMainIndex:{
            if (newspaperInfoViewController == nil) {
                newspaperInfoViewController = [[NewspaperInfoViewController alloc] initWithNibName:@"NewspaperInfoViewController" bundle:nil];
                newspaperInfoViewController.isHomePage = YES;
            }
            [self addChildViewController:newspaperInfoViewController];
            [self transitionFromViewController:self.currentViewController toViewController:newspaperInfoViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
        case kNewsIndex:{
//            if (newspaperViewController == nil) {
//                newspaperViewController = [[NewspaperViewController alloc] initWithNibName:@"NewspaperViewController" bundle:nil];
//            }
//            [self addChildViewController:newspaperViewController];
//            [self transitionFromViewController:self.currentViewController toViewController:newspaperViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
            
            
            if (jinRiMagazineViewController == nil) {
                jinRiMagazineViewController = [[JinRiMagazineViewController alloc] initWithNibName:@"JinRiMagazineViewController" bundle:nil];
            }
            [self addChildViewController:jinRiMagazineViewController];
            [self transitionFromViewController:self.currentViewController toViewController:jinRiMagazineViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];

        }
            break;
        case kMagazineIndex:{
            if (magazineViewController == nil) {
                magazineViewController = [[MagazineViewController alloc] initWithNibName:@"MagazineViewController" bundle:nil];
            }
            [self addChildViewController:magazineViewController];
            [self transitionFromViewController:self.currentViewController toViewController:magazineViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
        case kListenIndex:{
            if (listenViewController == nil) {
                listenViewController = [[ListenViewController alloc] initWithNibName:@"ListenViewController" bundle:nil];
            }
            [self addChildViewController:listenViewController];
            [self transitionFromViewController:self.currentViewController toViewController:listenViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
        case kNovelIndex:{
            if (novelViewController == nil) {
                novelViewController = [[NovelViewController alloc] initWithNibName:@"NovelViewController" bundle:nil];
            }
            [self addChildViewController:novelViewController];
            [self transitionFromViewController:self.currentViewController toViewController:novelViewController duration:0 options:UIViewAnimationOptionCurveEaseInOut animations:nil completion:nil];
        }
            break;
        default:
            break;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
